/*
**  Copyright (C), CHENGDU GONGWEI TECHNOLOGY CO.,LTD.
**
**  Project:	Manager Unit v1.0
**  File:    	
**  Author: 	zhuoguiming
**  Date:    	2017/05/20
**
**  Purpose:
**    		.
**
**  History: 
**  <author>   <time>          <version >   <desc>
*	$$Author$$
*/

#ifndef __NETWEBCGI_H__
#define __NETWEBCGI_H__

/* Include files. */
#include "standard.h"
#include "cplusplus.h"
#include "netobject.h"
#include <sstream>

/* Macro constant definitions. */

/* Type definitions. */

typedef enum FCGX_REQUEST_STATE{
	FCGX_REQUEST_WATING = 0,
	FCGX_REQUEST_READ_STR = 1,
	FCGX_REQUEST_READ_LINE = 2,
	FCGX_REQUEST_READ_LSTR = 3,
	FCGX_REQUEST_QUEUED = 4,
}FCGX_REQUEST_STATE;

class netWebcgi : public netObject 
{
public:
	netWebcgi(u32 ip, u16 port, u32 fd);
	virtual ~netWebcgi();
	virtual int bind();
	int recvMsg();
	int sendMsg();
public:
#ifdef U_LOOP
	int fcgxAccept(lua_State *L);
	int readLine(lua_State *L);
	int writeLine(lua_State *L);
	int sendSubSystem(const char *msg);
	int dumpCGIEnves(lua_State *L);
	virtual void accept();
public:
	struct FCGX_Request m_request;
	std::stringstream m_msgstream;
	size_t m_length;
	size_t m_receivedlen;
	struct json_object *m_msg;
	lua_State *m_L;
	int m_ref;
protected:
	FCGX_REQUEST_STATE m_state;
#endif

};

#ifdef U_LOOP
class luaContext{
protected:
	luaContext();
	~luaContext();
public:
	lua_State* getState();
	void unref(int k);
	int ref(int k);
public:
	static luaContext& getInstance();
protected:
	lua_State *m_L;
};
#endif




/* External variable declarations. */

/* External function declarations. */

/* Macro API definitions. */


#endif

